<?php

include_once (root . '/library/dictionary.php');

class HttpRequestHelper extends Dictionary {

     public $prikey = rss_prikey;

    public function __construct() {
        parent::__construct();
        return $this;
    }

    public function request() {
        foreach ($_REQUEST as $fields => $value) {
            $this[$fields] = $value;
        }
        $this->remove(array('action', 'usertoken', 'signtoken'));
        return $this;
    }

    //从COOKIE中获取KEY/VALUE对
    public function cookie($fields = array()) {
        if (count($fields)) {
            $fields = array_keys($_COOKIE);
        }
        foreach ($fields as $value) {
            $this->$value = isset($_COOKIE[$value]) ? $_COOKIE[$value] : null;
        }
        return $this;
    }

    public function verifysign() {
        $signtoken = $this['signtoken'];
        $this->clear('signtoken');

        return $this->md5sign($this->prikey) == $signtoken;
    }

    public function session($fields = array()) {
        foreach ($fields as $value) {
            $this->$value = $_SESSION[$value];
        }
        return $this;
    }

    public function getCookie($key) {
        return isset($_COOKIE[$key]) ? $_COOKIE[$key] : NULL;
    }

    public function rsscode(Exception $ex) {
        $this->keyvalue('rsscode', $ex->getMessage());
    }

}
